var fs = require('fs');
var {Buffer} = require('buffer');
// function to encode file data to base64 encoded string
function base64_encode(filePath) {
    console.log(Buffer.from);
  // read binary data
  var bitmap = fs.readFileSync(filePath);
  // convert binary data to base64 encoded string
  return Buffer.from(bitmap).toString('base64');
}

// function to create file from base64 encoded string
function base64_decode(base64str, filePath) {
  // create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
  var bitmap = Buffer.from(base64str, 'base64');
  // write buffer to file
  fs.writeFileSync(filePath, bitmap);
}

module.exports = {
    base64_encode,base64_decode
}
